<?php
class BaseContact extends Zend_Db_Table
{   
    protected $_name = "contact";
    
    /**
    * Class constructor
    * @return void
    */    
	function __construct($config = null){
        parent::__construct();
        
        
        $this->id = 0;
        
        $this->name = "";
        
        $this->email = "";
        
        $this->city = 0;
        
        $this->street = "";
        
        $this->state = "";
        
        $this->content = "";
        
    }
	
    function clearData()
    {
        
        $this->id = 0;
        
        $this->name = "";
        
        $this->email = "";
        
        $this->city = 0;
        
        $this->street = "";
        
        $this->state = "";
        
        $this->content = "";
        
    }
    
	/**
	All property of class
	*/
    
    /*
	* @declare   id of  Contact
	*/
    protected $id;
    
    /*
	* @declare   name of  Contact
	*/
    protected $name;
    
    /*
	* @declare   email of  Contact
	*/
    protected $email;
    
    /*
	* @declare   city of  Contact
	*/
    protected $city;
    
    /*
	* @declare   street of  Contact
	*/
    protected $street;
    
    /*
	* @declare   state of  Contact
	*/
    protected $state;
    
    /*
	* @declare   content of  Contact
	*/
    protected $content;
    
    
    /**
        All method of Contact
    */
    
    /**
     * @desc this method will set the value of the $id property
     * @param int  $id
     * @return void
     */
     function setId($id)
     {
        $this->id = $id;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $id property 
     * @param void
     * @return int of $id
     */
     function getId()
     {
        return  $this->id;
     } // end get function
     
    /**
     * @desc this method will set the value of the $name property
     * @param varchar  $name
     * @return void
     */
     function setName($name)
     {
        $this->name = $name;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $name property 
     * @param void
     * @return varchar of $name
     */
     function getName()
     {
        return  $this->name;
     } // end get function
     
    /**
     * @desc this method will set the value of the $email property
     * @param varchar  $email
     * @return void
     */
     function setEmail($email)
     {
        $this->email = $email;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $email property 
     * @param void
     * @return varchar of $email
     */
     function getEmail()
     {
        return  $this->email;
     } // end get function
     
    /**
     * @desc this method will set the value of the $city property
     * @param int  $city
     * @return void
     */
     function setCity($city)
     {
        $this->city = $city;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $city property 
     * @param void
     * @return int of $city
     */
     function getCity()
     {
        return  $this->city;
     } // end get function
     
    /**
     * @desc this method will set the value of the $street property
     * @param varchar  $street
     * @return void
     */
     function setStreet($street)
     {
        $this->street = $street;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $street property 
     * @param void
     * @return varchar of $street
     */
     function getStreet()
     {
        return  $this->street;
     } // end get function
     
    /**
     * @desc this method will set the value of the $state property
     * @param varchar  $state
     * @return void
     */
     function setState($state)
     {
        $this->state = $state;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $state property 
     * @param void
     * @return varchar of $state
     */
     function getState()
     {
        return  $this->state;
     } // end get function
     
    /**
     * @desc this method will set the value of the $content property
     * @param mediumtext  $content
     * @return void
     */
     function setContent($content)
     {
        $this->content = $content;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $content property 
     * @param void
     * @return mediumtext of $content
     */
     function getContent()
     {
        return  $this->content;
     } // end get function
       
     
     
     /**
     * @desc this function get Contact  by $id
     * @var int : $id 
     * @var 
     * @return Contact object
     */
     function getById($id)
     {
          $row = $this->fetchRow("id='$id'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Contact  by $name
     * @var varchar : $name 
     * @var 
     * @return Contact object
     */
     function getByName($name)
     {
          $row = $this->fetchRow("name='$name'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Contact  by $email
     * @var varchar : $email 
     * @var 
     * @return Contact object
     */
     function getByEmail($email)
     {
          $row = $this->fetchRow("email='$email'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Contact  by $city
     * @var int : $city 
     * @var 
     * @return Contact object
     */
     function getByCity($city)
     {
          $row = $this->fetchRow("city='$city'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Contact  by $street
     * @var varchar : $street 
     * @var 
     * @return Contact object
     */
     function getByStreet($street)
     {
          $row = $this->fetchRow("street='$street'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Contact  by $state
     * @var varchar : $state 
     * @var 
     * @return Contact object
     */
     function getByState($state)
     {
          $row = $this->fetchRow("state='$state'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Contact  by $content
     * @var mediumtext : $content 
     * @var 
     * @return Contact object
     */
     function getByContent($content)
     {
          $row = $this->fetchRow("content='$content'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
       
     
     // function save ".trimplural($table)." 
     public function save($forceInsert= false)
     { 
         if( $forceInsert == true)
            return $this->insert($this->toArray());
         $update = false;
         $condition = array(); 
        
        if($this->getId())
        {
            // is update
            $update = true;
            $condition[] = "id ='". $this->getId() ."'";
        }
        
         if( $update )   // update Contact
         {
            return $this->update($this->toArray(),implode(" and ",$condition));
         }
         else
         {
             $this->insert($this->toArray());
         }
     }
     /**
     * @desc this function get list of ".$table."
     * @var int : string $where condition, $page is current page, $rowCount is total row
     * @var 
     * @return user object
     */
     public function getListContact($where = null,$order = array(),$page = null ,$rowCount = null)
     {
        $select =  $this->select();
        if($where != null)
            $select->where($where);
         if($page===null)
             $select->from($this->_name);
        else
           $select->from($this->_name)->limitPage($page,$rowCount);
        $select->order($order);
        return $this->fetchAll($select);
     }     
     
     /**
     * @desc this method will import data from array 
     * @param void
     * @return array
     */
     function fromArray($array)
     {
        // import all proper ty
        
        if(isset($array["id"]))
                $this->id = $array["id"];
        
        if(isset($array["name"]))
                $this->name = $array["name"];
        
        if(isset($array["email"]))
                $this->email = $array["email"];
        
        if(isset($array["city"]))
                $this->city = $array["city"];
        
        if(isset($array["street"]))
                $this->street = $array["street"];
        
        if(isset($array["state"]))
                $this->state = $array["state"];
        
        if(isset($array["content"]))
                $this->content = $array["content"];
        
        // return object
        return $this;
     } // end export function
     
     /**
     * @desc this method will export data to array 
     * @param void
     * @return array
     */
     function toArray()
     {
        // import all proper ty
        $array = array();
        
        $array["id"] = $this->id;
        
        $array["name"] = $this->name;
        
        $array["email"] = $this->email;
        
        $array["city"] = $this->city;
        
        $array["street"] = $this->street;
        
        $array["state"] = $this->state;
        
        $array["content"] = $this->content;
        
        // return object
        return $array;
     } // end export function
     
    function numRows($where = null)
    {
        $select = $this->_db->select();
        $select->from($this->_name, "COUNT(*)", $this->_schema);
        // the WHERE clause
        $where = (array) $where;
        foreach ($where as $key => $val) {
            // is $key an int?
            if (is_int($key)) {
                // $val is the full condition
                $select->where($val);
            } else {
                // $key is the condition with placeholder,
                // and $val is quoted into the condition              
                $select->where($key, $val);           
            }          
        }
        // return the results
        $stmt = $this->_db->query($select);
        
        $data = $stmt->fetchColumn(0);       
        return $data;  
    }              
}